'''
测试登录oa
先通过html，拿到登录oa需要的东西
'''
from lxml import etree
from urllib import parse
import requests

    
base_url ="https://oa.kedacom.com"

# 先登录oa，拿到html
session = requests.Session()
resp = session.get(base_url)

html = etree.HTML(resp.text)

# 得到action
login_action = html.xpath("//form[@id='fm1']/@action[1]")

print(login_action[0])
# 这个是登录的url
login_url = parse.urljoin("https://sso.kedacom.com:8443",login_action[0])

loginTickets = html.xpath("//form[@id='fm1']//input[@name='loginTicket']/@value")

executions = html.xpath("//form[@id='fm1']//input[@name='execution']/@value")

login_ticket = loginTickets[0]
execution = executions[0]
print(login_ticket)
print(execution)

# print(login_url)
# 再拿到登录需要的其他东西
data = {
    "username":"wuqiang@kedacom.com",
    "password":"Wu415439280",
    "loginTicket":login_ticket,
    "execution":execution,
    "kdmoaAccount":"nice",
    "loginType":"web",
    "_eventId":"submit",
    "rememberMetest":True
}

print(f"login_url = {login_url},data = {data}")

# 登录
response = session.post(login_url,data=data)
print(f"----{response.status_code}")
#print(response.text)


# 将登录之后返回的代码保存下来



# 调用接口
test_url = "http://bear.kedacom.com/crm-web/loanConfirmationInstance/listData"

response = session.get(test_url)

print(response.text)

